package com.springcloud.music.demo.controller;


import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @ Author      : cyw
 * @ Date        : created in  下午7:53 2021/4/21
 * @ Description :
 * @ Modified By :
 * @Version : $
 */
@RestController
public class UserController {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "allCommentFB")
    @GetMapping("/user-service/comment")
    public Object allComment(){
        return restTemplate.getForObject("http://user-service/comment", List.class);
    }
    @HystrixCommand(fallbackMethod = "allCollectionFB")
    @GetMapping("/user-service/collection")
    public Object allCollection(){
        return restTemplate.getForObject("http://user-service/collection", List.class);
    }

    public Object allCommentFB(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","获取评论列表失败");
        return jsonObject;
    }
    public Object allCollectionFB(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        jsonObject.put("msg","获取收藏列表失败");
        return jsonObject;
    }
}
